package version2;

import java.util.Comparator;

public class ComparatorByStudentName implements Comparator<Student> {
  
    @Override
    public int compare(Student o1, Student o2) {
        Student stu1 = (Student)o1;
        Student stu2 = (Student)o2;
        // 先比较姓名，姓名相同再比较年龄
        int temp = stu1.getName().compareTo(stu2.getName());
        return temp == 0 ? stu1.getAge() - stu2.getAge() : temp;
    }
}
